Skip to content

Conversation

@Flo4604
Copy link
Member

@Flo4604 Flo4604 commented Oct 28, 2025

What does this PR do?

This cleans up the openapi spec for the credits, so they can be used by both keys and credits

Doesn't pass any tests either but its fine as we are using this as base for the next pr

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

Please double check if the schema makes sense in regards to nullability.

The api will throw a build error since the types got changed which is fixed in the next big pr

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2025

⚠️ No Changeset found

Latest commit: 36d3b2b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Oct 28, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
dashboard Ready Ready Preview Comment Nov 4, 2025 5:15pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
engineering Ignored Ignored Preview Nov 4, 2025 5:15pm

Copy link
Member Author

Flo4604 commented Oct 28, 2025

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This change refactors credit-related schemas and types across identities and keys in the OpenAPI specification and generated Go code. It introduces consolidated types (CreditInterval, CreditOperation, Credits, UpdateCredits, VerifyKeyIdentity) replacing key-specific variants, and integrates credits handling at both identity and key levels with new endpoints and modified request/response structures.

Changes

Cohort / File(s) Summary
Go Generated Types
go/apps/api/openapi/gen.go
Added new types: CreditInterval, CreditOperation, Credits, CreditsRefill, UpdateCredits, UpdateCreditsRefill, VerifyKeyIdentity, V2IdentitiesUpdateCreditsRequestBody, V2IdentitiesUpdateCreditsResponseBody. Modified field references to use Credits instead of KeyCreditsData; changed operation type to CreditOperation. Added Credits field to Identity struct. Removed V2KeysUpdateCreditsRequestBodyOperation type. Added JSON request/response body aliases.
OpenAPI Spec Files
go/apps/api/openapi/openapi-generated.yaml, go/apps/api/openapi/openapi-split.yaml
Updated schemas to reference new consolidated Credits types. Added new /v2/identities.updateCredits endpoint. Updated Identity, Key, and Verify request/response models to use new credit types and VerifyKeyIdentity.
Overlay Configuration
go/apps/api/openapi/overlay.yaml
Renamed KeyCreditsData → Credits, UpdateKeyCreditsData → UpdateCredits, UpdateKeyCreditsRefill → UpdateCreditsRefill. Updated property references and added nullable constraints to UpdateCreditsRefill.
Common Credit Schemas
go/apps/api/openapi/spec/common/CreditInterval.yaml, go/apps/api/openapi/spec/common/CreditOperation.yaml, go/apps/api/openapi/spec/common/Credits.yaml, go/apps/api/openapi/spec/common/CreditsRefill.yaml, go/apps/api/openapi/spec/common/UpdateCredits.yaml, go/apps/api/openapi/spec/common/UpdateCreditsRefill.yaml
Added new CreditInterval and CreditOperation enum schemas. Updated Credits and CreditsRefill to reference external CreditInterval schema. Introduced new UpdateCredits and UpdateCreditsRefill schemas supporting null semantics for disabling credits/refills.
Identity Schema & Endpoints
go/apps/api/openapi/spec/common/Identity.yaml, go/apps/api/openapi/spec/paths/v2/identities/createIdentity/..., go/apps/api/openapi/spec/paths/v2/identities/updateIdentity/..., go/apps/api/openapi/spec/paths/v2/identities/updateCredits/...
Added credits property to Identity schema. Extended V2IdentitiesCreateIdentityRequestBody and V2IdentitiesUpdateIdentityRequestBody with credits fields. Added new V2IdentitiesUpdateCreditsRequestBody/ResponseBody schemas and POST /v2/identities.updateCredits endpoint supporting set/increment/decrement operations.
Key Schemas & Endpoints
go/apps/api/openapi/spec/common/KeyResponseData.yaml, go/apps/api/openapi/spec/paths/v2/keys/createKey/..., go/apps/api/openapi/spec/paths/v2/keys/updateKey/..., go/apps/api/openapi/spec/paths/v2/keys/updateCredits/..., go/apps/api/openapi/spec/paths/v2/keys/verifyKey/...
Updated key credits references from KeyCreditsData to Credits. Changed V2KeysUpdateKeyRequestBody.credits reference from UpdateKeyCreditsData to UpdateCredits. Removed UpdateKeyCreditsData.yaml. Updated V2KeysUpdateCreditsRequestBody.operation to reference CreditOperation. Renamed operationId/x-speakeasy-name-override from updateCredits → updateKeyCredits. Updated V2KeysVerifyKeyResponseData.identity from Identity → VerifyKeyIdentity. Added new VerifyKeyIdentity schema with id, externalId, meta, and ratelimits fields.

Sequence Diagram

sequenceDiagram
    participant Client
    participant API
    participant Handler
    
    rect rgb(200, 220, 255)
    Note over Client,Handler: Identity-Level Credits Update (new)
    Client->>API: POST /v2/identities.updateCredits<br/>(identity, operation, value)
    API->>Handler: updateIdentityCredits<br/>(CreditOperation: set|increment|decrement)
    Handler->>Handler: Apply operation to identity credits<br/>(value or null for unlimited)
    Handler-->>API: Credits updated<br/>(remaining, refill)
    API-->>Client: 200 OK<br/>V2IdentitiesUpdateCreditsResponseBody
    end

    rect rgb(220, 200, 255)
    Note over Client,Handler: Key-Level Credits Update (refactored)
    Client->>API: PATCH /v2/keys/{keyId}/updateCredits<br/>(operation, value)
    API->>Handler: updateKeyCredits<br/>(CreditOperation: set|increment|decrement)
    Handler->>Handler: Apply operation to key credits<br/>(or identity-level credits if prioritized)
    Handler-->>API: Credits updated<br/>(Credits type)
    API-->>Client: 200 OK<br/>V2KeysUpdateCreditsResponseBody
    end

    rect rgb(200, 255, 220)
    Note over Client,Handler: Key Verification (identity shape refined)
    Client->>API: GET /v2/keys/{key}/verify
    API->>Handler: verifyKey
    Handler->>Handler: Validate key & retrieve identity
    Handler-->>API: VerifyKeyIdentity<br/>(id, externalId, meta, ratelimits)
    API-->>Client: 200 OK<br/>V2KeysVerifyKeyResponseData<br/>(includes VerifyKeyIdentity)
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas requiring extra attention:

  • Cross-references consistency: Verify all $ref updates from KeyCreditsData → Credits and UpdateKeyCreditsData → UpdateCredits are complete and correct across all endpoint definitions
  • Nullability semantics: Confirm null behavior for unlimited credits and disabled refills is correctly expressed in UpdateCredits and UpdateCreditsRefill schemas
  • Identity vs. key credit precedence: Validate that identity-level credits properly override key-level credits in implementation logic and documentation
  • New VerifyKeyIdentity type: Ensure all fields (id, externalId, meta, ratelimits) align with Identity schema expectations and don't break downstream consumers
  • CreditOperation enum usage: Confirm set/increment/decrement operations are correctly applied across both identity and key endpoints
  • Endpoint operation naming: Verify updateKeyCredits (renamed from updateCredits) doesn't conflict with identity's updateIdentityCredits operationId

Possibly related PRs

Suggested labels

Core Team

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description addresses the main template sections but has significant gaps that indicate incomplete work. The "What does this PR do?" section is brief and lacks the issue reference required by the template. The "Type of change" section correctly identifies this as a Chore. However, the "How should this be tested?" section provides only vague guidance ("Please double check if the schema makes sense in regards to nullability") rather than specific, reproducible test steps. Most critically, all required checklist items are unchecked, suggesting the author has not completed prerequisite tasks like running build/format commands, self-review, or merging latest changes from main. While the author acknowledges the PR intentionally doesn't pass tests because it's a base for the next PR in a stack, the incomplete checklist and vague testing instructions do not meet the description completeness standards. The description should be updated to include: (1) an issue reference (Fixes #XXXX) linking this work to a tracked issue; (2) specific, reproducible testing instructions beyond the vague "double check" request—for example, listing concrete validation steps for schema nullability and explaining how reviewers can verify the changes; and (3) checking off the required checklist items that have been completed, or explicitly explaining which items are deferred to the next PR in the stack. At minimum, clarify in "How should this be tested?" what specific schema elements should be validated and provide a clear path for testing, even if full CI/CD validation is deferred.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "feat: add identity-based credits OpenAPI specifications" is directly related to the changeset, which includes introducing identity-level credits support, new credit-related schemas (CreditInterval, CreditOperation, Credits, UpdateCredits), and updating OpenAPI specifications across multiple files. While the title emphasizes the identity-based aspect, the primary objective described in the PR is consolidating and refactoring the credits model so it can be used by both keys and identities. The title captures a significant and real part of these changes, though it doesn't fully represent the core refactoring goal of making credits generic and reusable across domains.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Flo4604 Flo4604 force-pushed the feat/identity-credits-openapi branch from ce27d21 to 19aadaf Compare October 28, 2025 21:09
@Flo4604 Flo4604 force-pushed the feat/identity-credits-openapi branch from 19aadaf to 03872fb Compare October 28, 2025 21:45
@Flo4604 Flo4604 force-pushed the feat/identity-credits-api-v1 branch from c300f90 to aa1950a Compare October 28, 2025 22:40
@Flo4604 Flo4604 force-pushed the feat/identity-credits-openapi branch from 03872fb to 6816e5e Compare October 28, 2025 22:40
@Flo4604 Flo4604 force-pushed the feat/identity-credits-api-v1 branch from aa1950a to baf6928 Compare October 29, 2025 09:59
@Flo4604 Flo4604 force-pushed the feat/identity-credits-openapi branch from 6816e5e to c199c71 Compare October 29, 2025 09:59
@Flo4604 Flo4604 force-pushed the feat/identity-credits-openapi branch from c199c71 to 7397a54 Compare October 29, 2025 10:21
@Flo4604 Flo4604 force-pushed the feat/identity-credits-api-v1 branch from 3369e55 to 8d4a3a4 Compare October 29, 2025 18:01
- object
- null
description: Configuration for automatic credit refill behavior.
- "null"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this null to "null" typo?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"null" and null is basically the same

When a key belonging to this identity is verified, credits are deducted from the identity's balance rather than individual key limits.
Essential for implementing usage-based billing and quota management at the user or organization level.
Identity credits take priority over key-level credits during verification.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this mean? are key credits still deducted?

Copy link
Member Author

@Flo4604 Flo4604 Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key credits are only deducted if the attached identity has no credits which means unlimited and the key has credits.

If the key has a identity with credits, we are going to decrement the credits of the identity

**Side Effects**
Credit updates take effect immediately. Setting credits to unlimited automatically clears any existing refill settings. Changes propagate instantly but may take up to 30 seconds to reach all edge regions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's contradicting itself, if it takes 30s, then it doesn't propagate instantly

@@ -0,0 +1,20 @@
type: object
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym, you omitted it entirely here, right? or what am I missing?

I agree, I don't want to pollute our response too much

@graphite-app
Copy link

graphite-app bot commented Nov 3, 2025

Ad gif. Sitting in front of an old computer, '90s child actor Brent Rambo gives a robust thumbs up to the camera, his mouth a confident upside-down crescent. His autograph is superimposed onto the scene, giving the impression that his stamp of approval truly matters.  (Added via Giphy)

@graphite-app
Copy link

graphite-app bot commented Nov 3, 2025

Graphite Automations

"Post a GIF when PR approved" took an action on this PR • (11/03/25)

1 gif was posted to this PR based on Andreas Thomas's automation.

- Add Credits and CreditsRefill schema definitions
- Add CreditOperation and CreditInterval enums
- Add updateCredits endpoints for keys and identities
- Update key and identity schemas to include credits field
- Add UpdateCredits and UpdateCreditsRefill request/response types
- Update generated OpenAPI specs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants